home *** CD-ROM | disk | FTP | other *** search
/ GFX Sensations 1 / Graphic Sensations - Volume 1.iso / tools / amiga / 3d_tools / irit40s.lha / Irit / cagd_lib / cagdedit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-30  |  2.6 KB  |  84 lines

  1. /******************************************************************************
  2. * CagdEdit.c - Editing tools of surfaces and Curves.                  *
  3. *******************************************************************************
  4. * Written by Gershon Elber, Sep. 91.                          *
  5. ******************************************************************************/
  6.  
  7. #include "cagd_loc.h"
  8.  
  9. /******************************************************************************
  10. * Modify a single control point in the curve.                      *
  11. ******************************************************************************/
  12. CagdCrvStruct *CagdEditSingleCrvPt(CagdCrvStruct *Crv, CagdCtlPtStruct *CtlPt,
  13.                            int Index, CagdBType Write)
  14. {
  15.     CagdBType
  16.     IsNotRational = !CAGD_IS_RATIONAL_CRV(Crv);
  17.     int i,
  18.     Length = Crv -> Length,
  19.     MaxCoord = CAGD_NUM_OF_PT_COORD(Crv -> PType);
  20.     CagdCrvStruct
  21.     *NewCrv = Write ? CagdCrvCopy(Crv) : NULL;
  22.     CagdRType
  23.     **Points = Write ? NewCrv -> Points : Crv -> Points;
  24.  
  25.     if (Index < 0 || Index >= Length)
  26.     FATAL_ERROR(CAGD_ERR_INDEX_NOT_IN_MESH);
  27.  
  28.     if (Write) {
  29.     if (Crv -> PType != CtlPt -> PtType)
  30.         FATAL_ERROR(CAGD_ERR_PT_OR_LEN_MISMATCH);
  31.  
  32.     for (i = IsNotRational; i <= MaxCoord; i++)
  33.         Points[i][Index] = CtlPt -> Coords[i];
  34.     }
  35.     else {
  36.         CtlPt -> PtType = Crv -> PType;
  37.  
  38.     for (i = IsNotRational; i <= MaxCoord; i++)
  39.         CtlPt -> Coords[i] = Points[i][Index];
  40.     }
  41.  
  42.     return NewCrv;
  43. }
  44.  
  45. /******************************************************************************
  46. * Modify a single control point in the surface.                      *
  47.  *****************************************************************************/
  48. CagdSrfStruct *CagdEditSingleSrfPt(CagdSrfStruct *Srf, CagdCtlPtStruct *CtlPt,
  49.                        int UIndex, int VIndex, CagdBType Write)
  50. {
  51.     CagdBType
  52.     IsNotRational = !CAGD_IS_RATIONAL_SRF(Srf);
  53.     int i,
  54.     ULength = Srf -> ULength,
  55.     VLength = Srf -> VLength,
  56.     MaxCoord = CAGD_NUM_OF_PT_COORD(Srf -> PType);
  57.     CagdSrfStruct
  58.     *NewSrf = Write ? CagdSrfCopy(Srf) : NULL;
  59.     CagdRType
  60.     **Points = Write ? NewSrf -> Points : Srf -> Points;
  61.  
  62.     if (UIndex < 0 || UIndex >= ULength ||
  63.     VIndex < 0 || VIndex >= VLength)
  64.     FATAL_ERROR(CAGD_ERR_INDEX_NOT_IN_MESH);
  65.  
  66.     if (Write) {
  67.     if (Srf -> PType != CtlPt -> PtType)
  68.         FATAL_ERROR(CAGD_ERR_PT_OR_LEN_MISMATCH);
  69.  
  70.     for (i = IsNotRational; i <= MaxCoord; i++)
  71.         Points[i][CAGD_MESH_UV(NewSrf, UIndex, VIndex)] =
  72.         CtlPt -> Coords[i];
  73.     }
  74.     else {
  75.         CtlPt -> PtType = Srf -> PType;
  76.  
  77.     for (i = IsNotRational; i <= MaxCoord; i++)
  78.         CtlPt -> Coords[i] =
  79.         Points[i][CAGD_MESH_UV(Srf, UIndex, VIndex)];
  80.     }
  81.  
  82.     return NewSrf;
  83. }
  84.